package com.neuedu.yyzx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.mapper.EmpMapper;
import com.neuedu.yyzx.po.Emp;
import com.neuedu.yyzx.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EmpServiceImpl implements EmpService {
	@Autowired
	private EmpMapper empMapper;
	public IPage<Emp> getPage(int curr,int size,String inputName,String inputHireDate) {
		IPage<Emp> page = new Page<Emp>(curr,size);
		QueryWrapper<Emp> qw = new QueryWrapper<>();
		if(inputName != null && (!inputName.equals(""))&&(!inputName.equals("null"))){
			qw.like("ename",inputName);
		}
		if(inputHireDate != null && (!inputHireDate.equals(""))&&(!inputHireDate.equals("null"))){
			qw.eq("hiredate",inputHireDate);
		}
		return empMapper.selectPage(page, qw);
	}
	public int addEmp(String ename,String job) {
		Emp emp = new Emp();
		emp.setEname(ename);
		emp.setJob(job);
		int num = this.empMapper.insert(emp);
		return num;
	}
	@Override
	public int addEmp(Emp userForm) {
		// TODO Auto-generated method stub
		return empMapper.insert(userForm);
	}
	@Override
	public int delUser(String empno) {
		// TODO Auto-generated method stub
		return empMapper.deleteById(empno);
	}
	@Override
	public int updateUser(Emp userForm) {
		// TODO Auto-generated method stub
		System.out.println(userForm.toString());
		return empMapper.updateById(userForm);
	}
	@Override
	public int delUserMany(String[] ids) {
		int num=0;
		for(int i=0;i<ids.length;i++) {
			num +=empMapper.deleteById(ids[i]);
		}
		return num;
	}
}
